#ifndef HelloOpenGLCommon_H
#define  HelloOpenGLCommon_H
#include <tchar.h>
#include <GL/glew.h>
// include DevIL for image loading
#include <IL/il.h>

typedef struct _Vertex3F
{
	float x;
	float y;
	float z;
} Vertex3F;
static Vertex3F vertex3(const float x, const float y, const float z)
{
	Vertex3F c = {x, y, z};
	return c;
}
static Vertex3F vertex3(const float x, const float y, const float z , const float scale)
{
	Vertex3F c = {x * scale, y * scale, z * scale};
	return c;
}
static Vertex3F vertex3(const float x, const float y, const float z , const float scale_x, const float scale_y, const float scale_z)
{
	Vertex3F c = {x * scale_x, y * scale_y, z * scale_z};
	return c;
}
typedef struct _Color4B
{
	GLubyte r;
	GLubyte g;
	GLubyte b;
	GLubyte a;
} Color4B;
static Color4B ccc4(const GLubyte r, const GLubyte g, const GLubyte b, const GLubyte a)
{
	Color4B c = {r, g, b, a};
	return c;
}
typedef struct _Tex2F {
	GLfloat u;
	GLfloat v;
} Tex2F;
static Tex2F tex2(const float u, const float v)
{
	Tex2F t = {u , v};
	return t;
}
typedef struct _V3F_C4B_T2F
{
	//! vertices (3F)
	Vertex3F        vertices;            // 12 bytes
	//    char __padding__[4];

	//! colors (4B)
	Color4B        colors;                // 4 bytes
	//    char __padding2__[4];

	// tex coords (2F)
	Tex2F            texCoords;            // 8 bytes
} V3F_C4B_T2F;
typedef struct _V3F_C4B_T2F_Quad
{
	//! top left
	V3F_C4B_T2F    tl;
	//! bottom left
	V3F_C4B_T2F    bl;
	//! top right
	V3F_C4B_T2F    tr;
	//! bottom right
	V3F_C4B_T2F    br;
	GLuint tex;
} V3F_C4B_T2F_Quad;
namespace HelloOpenGLCommon {
	char *textFileRead(char *fn);
	void textFileWrite(char *fn, char *s);
	int genSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals, 
		GLfloat **texCoords, GLuint **indices );
	int  genCube ( float scale, GLfloat **vertices, GLfloat **normals, 
		GLfloat **texCoords, GLuint **indices );
	void genRect(GLfloat** vertices,GLushort** indices);
	void genRectQuad(V3F_C4B_T2F_Quad** quad);
	void genRectQuad2(V3F_C4B_T2F_Quad** quad,float scale);
	void genRectQuad3(V3F_C4B_T2F_Quad** quad,float scale);
	GLuint loadShader ( GLenum type, const char *shaderSrc );
	GLuint loadTexture ( char *fileName );
	char* loadTGA ( char *fileName, int *width, int *height );
	GLuint loadProgram ( const char *vertShaderSrc, const char *fragShaderSrc );
	void renderQuad(const V3F_C4B_T2F_Quad* quad);
}

#endif
